package com.crois.barrier.web.resp;

/**
 * @author Hou Ze Yu
 * @description
 * @date 2020/10/23
 */

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Objects;

/**
 * @author Hou Ze Yu
 * @description Door 返回 公共类
 * @date 2020/7/22
 */
public class BarrierResponseUtils {
    /**
     * Error mono.
     *
     * @param exchange the exchange
     * @param result    the result
     * @return the mono
     */
    public static Mono<Void> error(final ServerWebExchange exchange, final Object result) {
        return exchange.getResponse().writeWith(Mono.just(exchange.getResponse()
                .bufferFactory().wrap(Objects.requireNonNull(JSONObject.toJSONString(result)).getBytes())));
    }
    /**
     * Success mono.
     *
     * @param exchange the exchange
     * @param result    the result
     * @return the mono
     */
    public static Mono<Void> success(final ServerWebExchange exchange, final Object result) {
        return exchange.getResponse().writeWith(Mono.just(exchange.getResponse()
                .bufferFactory().wrap(Objects.requireNonNull(JSONObject.toJSONString(result)).getBytes())));
    }
}
